home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SoundComponents.h
-
- Contains: Prototypes for Sound Components
-
- Written by: Jim Reekes and Kip Olson
-
- Copyright: ) 1991-1994 by Apple Computer, Inc., all rights reserved.
- */
-
- #ifndef __SOUNDCOMPONENTS__
- #define __SOUNDCOMPONENTS__
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // C include files cannot be used by Rez
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- #ifndef forRez
-
- #include <Components.h>
- #include <Sound.h>
-
- #endif
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // constants
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- // sound component types and subtypes
-
- #define kNoSoundComponentType '****'
-
- #define kSoundComponentType 'sift'
- #define kRate8SubType 'ratb' /* 8-bit rate converter */
- #define kRate16SubType 'ratw' /* 16-bit rate converter */
- #define kConverterSubType 'conv' /* sample format converter */
- #define kSndSourceSubType 'sour' /* generic source component */
-
- #define kMixerType 'mixr'
- #define kMixer8SubType 'mixb' /* 8-bit mixer */
- #define kMixer16SubType 'mixw' /* 16-bit mixer */
-
- // these component types must match the gestaltSoundHardware result
- #define kClassicSubType 'clas' /* "classic" hardware, i.e. Mac + */
- #define kASCSubType 'asc ' /* Apple Sound Chip device */
- #define kDSPSubType 'dsp ' /* DSP device */
- #define kAwacsSubType 'awac' /* Another of Will's Audio Chips device */
- #define kSingerSubType 'sing' /* Singer (via Whitney) based sound (Blackbird) */
-
- #define kSoundCompressor 'scom'
- #define kSoundDecompressor 'sdec'
- #define kMace3SubType 'MAC3' /* MACE 3:1 */
- #define kMace6SubType 'MAC6' /* MACE 6:1 */
- #define kCDXA4SubType 'CDX4' /* CD/XA 4:1 */
- #define kCDXA2SubType 'CDX2' /* CD/XA 2:1 */
-
- #define kSoundComponentCodeType kSoundComponentType /* code for the sound components */
-
- // Audio components and sub-types
- #define kAudioComponentType 'adio'
- #define kAudioCodeType kAudioComponentType
- #define kAwacsPhoneSubType 'hphn'
- #define kTeleSpeakerSubType 'telc'
- #define kTeleHeadphoneSubType 'telh'
-
- // sound component set/get info selectors
- #define siVolume 'volu'
- #define siHardwareVolume 'hvol'
- #define siSpeakerVolume 'svol'
- #define siHeadphoneVolume 'pvol'
- #define siHardwareVolumeSteps 'hstp'
- #define siHeadphoneVolumeSteps 'hdst'
- #define siHardwareMute 'hmut'
- #define siSpeakerMute 'smut'
- #define siHeadphoneMute 'pmut'
- #define siRateMultiplier 'rmul'
- #define siQuality 'qual'
-
- // format types
- #define kOffsetBinary 'raw '
- #define kTwosComplement 'twos'
- #define kMACE3Compression 'MAC3'
- #define kMACE6Compression 'MAC6'
-
- // quality flags
- #define kBestQuality (1 << 0) /* use interpolation in rate conversion */
-
- // features flags
- #define k8BitRawIn (1 << 0) /* data description */
- #define k8BitTwosIn (1 << 1)
- #define k16BitIn (1 << 2)
- #define kStereoIn (1 << 3)
- #define k8BitRawOut (1 << 8)
- #define k8BitTwosOut (1 << 9)
- #define k16BitOut (1 << 10)
- #define kStereoOut (1 << 11)
-
- #define kReverse (1 << 16) /* function description */
- #define kRateConvert (1 << 17)
- #define kCreateSoundSource (1 << 18)
-
- #define kHighQuality (1 << 22) /* performance description */
- #define kRealTime (1 << 23)
-
- #define kInputMask 0x000000FF /* masks off input bits */
- #define kOutputMask 0x0000FF00 /* masks off output bits */
- #define kOutputShift 8 /* amount output bits are shifted */
- #define kActionMask 0x00FF0000 /* masks off action bits */
- #define kSoundComponentBits 0x00FFFFFF
-
-
- // SoundComponentPlaySourceBuffer action flags
- #define kSourcePaused (1 << 0)
-
- #define kPassThrough (1 << 16)
- #define kNoSoundComponentChain (1 << 17)
-
- // flags for OpenMixerSoundComponent
- #define kNoMixing (1 << 0) /* don't mix source */
- #define kNoSampleRateConversion (1 << 1) /* don't convert sample rate (i.e. 11 kHz -> 22 kHz) */
- #define kNoSampleSizeConversion (1 << 2) /* don't convert sample size (i.e. 16 -> 8) */
- #define kNoSampleFormatConversion (1 << 3) /* don't convert sample format (i.e. 'twos' -> 'raw ') */
- #define kNoChannelConversion (1 << 4) /* don't convert stereo/mono */
- #define kNoDecompression (1 << 5) /* don't decompress (i.e. 'MAC3' -> 'raw ') */
- #define kNoVolumeConversion (1 << 6) /* don't apply volume */
- #define kNoRealtimeProcessing (1 << 7) /* won't run at interrupt time */
-
-
- // Audio Component constants
-
- // Values for whichChannel parameter
- #define audioAllChannels 0 /* All channels (usually interpreted as both left and right) */
- #define audioLeftChannel 1 /* Left channel */
- #define audioRightChannel 2 /* Right channel */
-
- // Values for mute parameter
- #define audioUnmuted 0 /* Device is unmuted */
- #define audioMuted 1 /* Device is muted */
-
- // Capabilities flags definitions
- #define audioDoesMono (1L<<0) /* Device supports mono output */
- #define audioDoesStereo (1L<<1) /* Device supports stereo output */
- #define audioDoesIndependentChannels (1L<<2) /* Device supports independent software control of each channel */
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // typedefs
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- // typedefs cannot be used by Rez
- #ifndef forRez
-
- // This type consists of an 8 bit, 2's complement integer part in the high byte,
- // with an 8 bit fractional part in the low byte; its range is -128 to 127.99609375
- typedef short ShortFixed;
-
- typedef struct SoundComponentData SoundComponentData;
- typedef struct SoundComponentData *SoundComponentDataPtr;
-
- struct SoundComponentData {
- long flags;
- OSType format;
- short numChannels;
- short sampleSize;
- UnsignedFixed sampleRate;
- long sampleCount;
- Byte *buffer;
- long reserved;
- };
-
- typedef struct SoundParamBlock SoundParamBlock;
- typedef SoundParamBlock *SoundParamBlockPtr;
-
- typedef pascal Boolean (*SoundParamProcPtr)(SoundParamBlockPtr *pb);
-
- struct SoundParamBlock {
- long recordSize; // size of this record in bytes
- SoundComponentData desc; // description of sound buffer
- Fixed rateMultiplier; // rate multiplier to apply to sound
- short leftVolume; // volumes to apply to sound
- short rightVolume;
- long quality; // quality to apply to sound
- ComponentInstance filter; // filter to apply to sound
- SoundParamProcPtr moreRtn; // routine to call to get more data
- SoundParamProcPtr completionRtn; // routine to call when buffer is complete
- long refCon; // user refcon
- short result; // result
- };
-
- // private thing to use as a reference to a chain
- typedef struct privateSoundSource *SoundSource;
-
- typedef struct CompressionInfo CompressionInfo;
- typedef CompressionInfo *CompressionInfoPtr;
- typedef CompressionInfoPtr *CompressionInfoHandle;
-
- struct CompressionInfo {
- long recordSize;
- OSType format;
- short compressionID;
- short samplesPerPacket;
- short bytesPerPacket;
- short bytesPerFrame;
- short bytesPerSample;
- short futureUse1;
- };
-
- typedef struct AudioInfo AudioInfo;
- typedef AudioInfo *AudioInfoPtr;
-
- struct AudioInfo {
- long capabilitiesFlags; // Describes device capabilities
- long reserved; // Reserved by Apple
- unsigned short numVolumeSteps; // Number of significant increments between min and max volume
- };
-
-
- #endif
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // functions for sound components
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- // routines cannot be used by Rez
- #ifndef forRez
-
- #define kDelegatedSoundComponentSelectors 0x0100 /* first selector that can be delegated up the chain*/
-
- // Sound Component dispatch selectors
- enum {
- kSoundComponentInitOutputDeviceSelect = 1, /* these calls cannot be delegated */
- kSoundComponentSetSourceSelect,
- kSoundComponentGetSourceSelect,
- kSoundComponentGetSourceDataSelect,
- kSoundComponentSetOutputSelect,
- /* these calls can be delegated */
- kSoundComponentAddSourceSelect = kDelegatedSoundComponentSelectors + 1,
- kSoundComponentRemoveSourceSelect,
-
- kSoundComponentGetInfoSelect,
- kSoundComponentSetInfoSelect,
-
- kSoundComponentStartSourceSelect,
- kSoundComponentStopSourceSelect,
- kSoundComponentPauseSourceSelect,
- kSoundComponentPlaySourceBufferSelect
- };
-
- // Audio Component selectors
- enum {
- kAudioGetVolumeSelect = 0,
- kAudioSetVolumeSelect,
- kAudioGetMuteSelect,
- kAudioSetMuteSelect,
- kAudioSetToDefaultsSelect,
- kAudioGetInfoSelect,
- kAudioMuteOnEventSelect = 129
- };
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // Sound Manager 3.0 utilities
-
- pascal OSErr OpenMixerSoundComponent(SoundComponentDataPtr outputDescription, long outputFlags, ComponentInstance *mixerComponent)
- = {0x203C,0x0614,0x0018,0xA800};
-
- pascal OSErr CloseMixerSoundComponent(ComponentInstance ci)
- = {0x203C,0x0218,0x0018,0xA800};
-
-
- #ifndef __cplusplus
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // basic sound component functions
-
- pascal ComponentResult SoundComponentInitOutputDevice(ComponentInstance ti, long actions)
- = ComponentCallNow(kSoundComponentInitOutputDeviceSelect, sizeof(long));
-
- pascal ComponentResult SoundComponentSetSource(ComponentInstance ti, SoundSource sourceID, ComponentInstance source)
- = ComponentCallNow(kSoundComponentSetSourceSelect, sizeof(SoundSource) + sizeof(ComponentInstance));
-
- pascal ComponentResult SoundComponentGetSource(ComponentInstance ti, SoundSource sourceID, ComponentInstance *source)
- = ComponentCallNow(kSoundComponentGetSourceSelect, sizeof(SoundSource) + sizeof(ComponentInstance));
-
- pascal ComponentResult SoundComponentGetSourceData(ComponentInstance ti, SoundComponentDataPtr *sourceData)
- = ComponentCallNow(kSoundComponentGetSourceDataSelect, sizeof(SoundComponentDataPtr));
-
- pascal ComponentResult SoundComponentSetOutput(ComponentInstance ti, SoundComponentDataPtr requested, SoundComponentDataPtr *actual)
- = ComponentCallNow(kSoundComponentSetOutputSelect, sizeof(SoundComponentDataPtr) + sizeof(SoundComponentDataPtr));
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // junction methods for the mixer, must be called at non-interrupt level
-
- pascal ComponentResult SoundComponentAddSource(ComponentInstance ti, SoundSource *sourceID)
- = ComponentCallNow(kSoundComponentAddSourceSelect, sizeof(SoundSource));
-
- pascal ComponentResult SoundComponentRemoveSource(ComponentInstance ti, SoundSource sourceID)
- = ComponentCallNow(kSoundComponentRemoveSourceSelect, sizeof(SoundSource));
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // info methods
-
- pascal ComponentResult SoundComponentGetInfo(ComponentInstance ti, SoundSource sourceID, OSType selector, void *infoPtr)
- = ComponentCallNow(kSoundComponentGetInfoSelect, sizeof(SoundSource) + sizeof(OSType) + sizeof(Ptr));
-
- pascal ComponentResult SoundComponentSetInfo(ComponentInstance ti, SoundSource sourceID, OSType selector, void *infoPtr)
- = ComponentCallNow(kSoundComponentSetInfoSelect, sizeof(SoundSource) + sizeof(OSType) + sizeof(Ptr));
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // control methods
-
- pascal ComponentResult SoundComponentStartSource(ComponentInstance ti, short count, SoundSource *sources)
- = ComponentCallNow(kSoundComponentStartSourceSelect, sizeof(short) + sizeof(SoundSource));
-
- pascal ComponentResult SoundComponentStopSource(ComponentInstance ti, short count, SoundSource *sources)
- = ComponentCallNow(kSoundComponentStopSourceSelect, sizeof(short) + sizeof(SoundSource));
-
- pascal ComponentResult SoundComponentPauseSource(ComponentInstance ti, short count, SoundSource *sources)
- = ComponentCallNow(kSoundComponentPauseSourceSelect, sizeof(short) + sizeof(SoundSource));
-
- pascal ComponentResult SoundComponentPlaySourceBuffer(ComponentInstance ti, SoundSource sourceID,
- SoundParamBlockPtr pb, long actions)
- = ComponentCallNow(kSoundComponentPlaySourceBufferSelect, sizeof(SoundSource)
- + sizeof(SoundParamBlockPtr) + sizeof(long));
-
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // interface for Audio Components
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- // Volume is described as a value between 0 and 1, with 0 indicating minimum
- // volume and 1 indicating maximum volume; if the device doesn't support
- // software control of volume, then a value of unimpErr is returned, indicating
- // that these functions are not supported by the device
- pascal ComponentResult AudioGetVolume(ComponentInstance ac, short whichChannel, ShortFixed *volume)
- = ComponentCallNow(kAudioGetVolumeSelect, sizeof(short) + sizeof(Ptr));
-
- pascal ComponentResult AudioSetVolume(ComponentInstance ac, short whichChannel, ShortFixed volume)
- = ComponentCallNow(kAudioSetVolumeSelect, sizeof(short) + sizeof(ShortFixed));
-
- // If the device doesn't support software control of mute, then a value of
- // unimpErr is returned, indicating that these functions are not supported
- // by the device
- pascal ComponentResult AudioGetMute(ComponentInstance ac, short whichChannel, short *mute)
- = ComponentCallNow(kAudioGetMuteSelect, sizeof(short) + sizeof(Ptr));
-
- pascal ComponentResult AudioSetMute(ComponentInstance ac, short whichChannel, short mute)
- = ComponentCallNow(kAudioSetMuteSelect, sizeof(short) + sizeof(short));
-
- // AudioSetToDefaults causes the associated device to reset its volume
- // and mute values (and perhaps other private characteristics, e.g.
- // attenuation) to "factory default" settings
- pascal ComponentResult AudioSetToDefaults(ComponentInstance ac)
- = ComponentCallNow(kAudioSetToDefaultsSelect, 0);
-
- // This routine is required; it must be implemented by all audio components
- pascal ComponentResult AudioGetInfo(ComponentInstance ac, AudioInfoPtr info)
- = ComponentCallNow(kAudioGetInfoSelect, sizeof(AudioInfoPtr));
-
-
- // I found this original without the ComponentResult defined as the function's result (?)
-
- // This is routine is private to the AudioVision component. It enables
- // the watching of the mute key.
- pascal ComponentResult AudioMuteOnEvent(ComponentInstance ac, short muteOnEvent)
- = ComponentCallNow(kAudioMuteOnEventSelect, sizeof(short));
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
-
- // if not for Rez
- #endif
-
- // if already included
- #endif
-